<template>
<div>
<el-table
    :data="categroyList"
    style="width: 100%"
    row-key="id"
    border
    lazy
    :load="load"
    :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
    <el-table-column
      prop="id"
      label="分类ID"
      width="120"
      
      sortable>
    </el-table-column>
    <el-table-column
      prop="name"
      label="分类名"
      >
    </el-table-column>
    <el-table-column >
    <!-- <el-table-column label="操作" width="180"> -->

      <template slot="header">
        <el-input value="未有功能实现"></el-input>
      </template>

      <template slot-scope="row,$index">
        <Lzbutton  type="primary" icon="el-icon-plus" title="添加"></Lzbutton>
        <Lzbutton  type="primary" icon="el-icon-edit" title="修改"></Lzbutton>
        <Lzbutton  type="danger" icon="el-icon-delete" title="删除"></Lzbutton>
      </template>
    </el-table-column>
  </el-table>
</div>

</template>
<script>
  export default {
    name:'manageCategory',
    data() {
      return {
        categroyList : [],
        
      }
    },
    methods: {
      async load(tree, treeNode, resolve) {
        // 获取二级分类
        try{
          let rd2= await this.$api.category.reqCategory2nd(tree.category)
          if(rd2.status ===200){
            resolve(rd2.data)
          }
        }catch{

        }
        
      },
      // 获取默认数据
     async getDefault(){
       let result  = await this.$api.category.reqCategory1st()
       let cc = result.data.map(item =>{ 
         item.hasChildren=true
         item.children =[]
         return item
         })
      //  hasChildren
       this.categroyList = cc

     
      }      
    },
    beforeMount(){
      this.getDefault()
    }
  }

  </script>